"""
核心配置模块
"""

from pydantic_settings import BaseSettings
from typing import Optional
import os
from functools import lru_cache


class Settings(BaseSettings):
    """应用配置类"""
    
    # 基础配置
    DEBUG: bool = True
    LOG_LEVEL: str = "INFO"
    
    # 数据库配置
    DATABASE_URL: str = "sqlite:///./auto_post.db"
    
    # Redis配置
    REDIS_URL: str = "redis://localhost:6379/0"
    
    # AI API配置
    OPENAI_API_KEY: Optional[str] = None
    OPENAI_MODEL: str = "gpt-3.5-turbo"
    
    # 通义千问API配置
    QWEN_API_KEY: Optional[str] = None
    QWEN_MODEL: str = "qwen-plus-latest"
    
    # 平台API配置
    WEIBO_APP_KEY: Optional[str] = None
    WEIBO_APP_SECRET: Optional[str] = None
    WEIBO_ACCESS_TOKEN: Optional[str] = None
    
    TWITTER_API_KEY: Optional[str] = None
    TWITTER_API_SECRET: Optional[str] = None
    TWITTER_ACCESS_TOKEN: Optional[str] = None
    TWITTER_ACCESS_TOKEN_SECRET: Optional[str] = None
    
    # 任务调度配置
    SCHEDULE_ENABLED: bool = True
    DEFAULT_SCHEDULE_INTERVAL: int = 1800  # 30分钟
    
    # 内容生成配置
    MAX_CONTENT_LENGTH: int = 280
    CONTENT_TEMPLATES_PATH: str = "./config/templates/"
    SENSITIVE_WORDS_PATH: str = "./config/sensitive_words.txt"
    
    # 热点抓取配置
    WEIBO_HOT_URL: str = "https://s.weibo.com/top/summary"
    ZHIHU_HOT_URL: str = "https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total"
    BAIDU_HOT_URL: str = "https://top.baidu.com/board?tab=realtime"
    
    class Config:
        env_file = ".env"
        case_sensitive = True


@lru_cache()
def get_settings() -> Settings:
    """获取配置实例（单例模式）"""
    return Settings()